package com.ck.email.controller;

import com.ck.common.constant.AjaxResult;
import com.ck.email.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ck
 * @date 2023/6/9 11:53
 */


@RestController
public class EmailController {

    @Autowired
    private EmailService emailService;

    @Value("${spring.mail.receive}")
    private String receive;


    /**
     * 普通文本邮件
     */
    @PostMapping("/emailTestOne")
    public AjaxResult sendSimpleEmail(){
        String content = "你好，恭喜你...";
        String[] split = receive.split(",");
        emailService.sendSimpleMail(split,"祝福邮件",content);
        return  new AjaxResult(200,"发送成功");
    }

    /**
     * html邮件
     */
    @PostMapping("emailTestTwo")
    public AjaxResult sendMimeEmail(){
        String content = "<a href='https://blog.csdn.net/'>你好，欢迎注册网站，请点击链接激活</a>";
        String[] split = receive.split(",");
        emailService.sendHtmlMail(split,"激活邮件",content);
        return  new AjaxResult(200,"发送成功");
    }


    /**
     * 附件邮件
     */
    @PostMapping("emailTestThree")
    public AjaxResult sendAttachment(){
        String[] split = receive.split(",");
        emailService.sendAttachmentsMail(split,"发送附件","这是Excel数据表","D:\\write.xlsx");
        return  new AjaxResult(200,"发送成功");
    }
}
